using System;

namespace Lichtspiel.ECSystem.Behaviors
{
    public class BehaviorSequence : BehaviorHolder
    {
        public BehaviorSequence()
            : base() { }


        public BehaviorSequence(Action finished)
            : base(finished) {}

        public override void Update(GameTime time) {
            base.Update(time);

            if (behaviors.Count > 0) {
                behaviors[0].Update(time);
            }
        }

        protected override void Initialize() {
            base.Initialize();

            InitNextBehavior();
        }

        internal override void BehaviorFinished(Behavior behavior) {
            base.BehaviorFinished(behavior);

            InitNextBehavior();
        }

        private void InitNextBehavior() {
            if (behaviors.Count > 0) {
                behaviors[0].Initialize(owner, this);
            }
        }
    }
}